//
//  LBTestLoopSubView.m
//  LBLoopScrollView
//
//  Created by LINAICAI on 2017/6/20.
//  Copyright © 2017年 LINAICAI. All rights reserved.
//

#import "LBTestLoopSubView.h"
#import "UIPageControl+LBLoopScrollView.h"
#import <SDWebImage/UIImageView+WebCache.h>
@interface LBTestLoopSubView()<LBLoopScrollViewDelegate>

@end
@implementation LBTestLoopSubView
- (UILabel *)pageLabel{
    if (!_pageLabel) {
        _pageLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 10, 100, 40)];
        _pageLabel.backgroundColor = [UIColor whiteColor];
        _pageLabel.textColor = [UIColor grayColor];
        _pageLabel.layer.cornerRadius = 8;
        _pageLabel.layer.masksToBounds = YES;
    }
    return _pageLabel;
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
    }
    return self;
}
- (void)prepareDisplay{
    [self addSubview:self.pageLabel];
    if (self.originSources.count <=1) {
        self.pageLabel.hidden = YES;
    }
    else{
        self.pageLabel.hidden = NO;
    }
    self.pageLabel.text = [NSString stringWithFormat:@"%ld/%ld",self.pageControl.currentPage+1,self.pageControl.numberOfPages];
}
- (void)layoutSubviews{
    [super layoutSubviews];
    [self setDelegate:(id<LBLoopScrollViewDelegate>)self];
    self.pageControl.frame = CGRectMake(0, 0, self.superview.bounds.size.width, 50);
}
//轮播组件点击回调
- (void)LBLoopScrollViewDidClickWithIndex:(NSInteger)index{
    
}
//轮播组件页码改变时回调
- (void)LBLoopScrollViewChageCurrentPageWithIndex:(NSInteger)index{
    
    self.pageLabel.text = [NSString stringWithFormat:@"%ld/%ld",self.pageControl.currentPage+1,self.pageControl.numberOfPages];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
//通过代理设置数据源
- (NSArray *)LBLoopScrollViewDataSources{
    return @[@"https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=1708877790,1437461839&fm=80&w=179&h=119&img.JPEG",
             @"http://img1.gtimg.com/news/pics/hv1/247/36/2217/144169852.jpg",
             @"http://img.jiankang.com/temp/2017/06/14/14974282237125.jpg",
             @"http://img0.utuku.china.com/640x0/news/20170613/19e23c3b-22ca-4001-9c95-7a8218629cf2.jpg"
             ];
}
@end
